/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import com.opensymphony.xwork2.ActionContext;
import java.math.BigInteger;
import java.util.Map;
import models.AccountBO;
import models.PostBO;
import myconfession.dto.account.Account;
import myconfession.dto.post.Post;
import myconfession.utils.FacebookUtil;

/**
 *
 * @author Liem
 */
public class UnpostAction {

    private String id;
    private String returnUrl;

    public UnpostAction() {
    }

    public String execute() throws Exception {
        Map session = ActionContext.getContext().getSession();
        String username = (String) session.get("USER");
        if (username != null) {

            Post post = PostBO.getPostById(new BigInteger(id));
            Account acc = AccountBO.getAccountByUsername(username);
            if (FacebookUtil.removePostOn(post.getFbPostId(), acc.getFbToken())) {
                PostBO.unpost(Integer.parseInt(id));
            }
        }

        return "success";
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getReturnUrl() {
        return returnUrl;
    }

    public void setReturnUrl(String returnUrl) {
        this.returnUrl = returnUrl;
    }
}
